package com.jvyou.app.ds.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jvyou.app.common.enums.HttpCodeEnum;
import com.jvyou.app.common.exception.AppException;
import com.jvyou.app.ds.domain.entity.AnswerRecord;
import com.jvyou.app.ds.domain.entity.Question;
import com.jvyou.app.ds.domain.entity.Student;
import com.jvyou.app.ds.mapper.AnswerRecordMapper;
import com.jvyou.app.ds.mapper.QuestionMapper;
import com.jvyou.app.ds.mapper.StudentMapper;
import com.jvyou.app.ds.service.AnswerRecordService;
import com.jvyou.app.ds.utils.login.LoginContext;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;


/**
 * 学员答题记录表(AnswerRecord)表服务实现类
 *
 * @author 橘柚
 * @since 2025-04-21 20:37:57
 */
@RequiredArgsConstructor
@Service("answerRecordService")
public class AnswerRecordServiceImpl extends ServiceImpl<AnswerRecordMapper, AnswerRecord> implements AnswerRecordService {

    private final StudentMapper studentMapper;
    private final QuestionMapper questionMapper;

    @Override
    public AnswerRecord insertAnswerRecord(AnswerRecord answerRecord) {
        Long userId = LoginContext.getUserId();
        Student student = studentMapper.getByUser(userId);
        if (student==null){
            throw new AppException(HttpCodeEnum.DATA_NOT_EXIST,"学员信息异常");
        }
        answerRecord.setStudentId(student.getId());
        save(answerRecord);
        return answerRecord;
    }
}
